package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.ItemCatDao;
import ysq.xyg.model.ItemCat;
import ysq.xyg.service.ItemCatService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品分类实现
 *
 * @author congcong tao
 * @date 2018/8/7 11:46
 */
@Service("itemCatService")
public class ItemCatServiceImpl extends BaseServiceImpl<ItemCat> implements ItemCatService {

    @Resource
    private ItemCatDao itemCatDao;
    @Autowired
    public void setItemCatDao(ItemCatDao itemCatDao) {
        this.baseDao = itemCatDao;
    }

    @Override
    public PageInfo<ItemCat> pageInfo(ItemCat itemCat, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        // 通用Example查询
        Example example = new Example(ItemCat.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(itemCat.getName())) {
            criteria.andLike("name", "%" + itemCat.getName() + "%");
        }
        example.orderBy("sortOrder asc");
        List<ItemCat> list = itemCatDao.selectByExample(example);
        return new PageInfo<ItemCat>(list);
    }
}
